package com.openx.cloud.server.autoconfigure.security.oauth2;

import cn.hutool.crypto.digest.DigestUtil;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.code.InMemoryAuthorizationCodeServices;

import java.util.UUID;

/**
 * 自定义认证码生成类
 *
 * @author yadu
 */
public class Sha1AuthorizationCodeServices extends InMemoryAuthorizationCodeServices {
    /**
     * 重写code生成规则
     *
     * @param authentication
     * @return
     */
    @Override
    public String createAuthorizationCode(OAuth2Authentication authentication) {
        String code = DigestUtil.sha1Hex(UUID.randomUUID().toString());
        this.store(code, authentication);
        return code;
    }


}
